package com.axiu;


import android.app.Activity;
import android.app.AlertDialog;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.Toast;


/**
 * A simple {@link Fragment} subclass.
 */
public class SettingsFragment extends Fragment {

    private AlertDialog myDialog = null;

    public SettingsFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        TextView title = (TextView) this.getActivity().findViewById(R.id.top_bar_title);
        title.setText("系统管理");
        View view = inflater.inflate(R.layout.fragment_settings, container, false);
        TextView exit_view = (TextView) view.findViewById(R.id.exit);
        exit_view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showExitDialog(getActivity());
            }
        });
        final SwitchButton update = (SwitchButton) view.findViewById(R.id.update_switch);
        update.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

            }
        });

        Button explainBtn = (Button) view.findViewById(R.id.explain_btn);
        explainBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), ExplainActivity.class);
                startActivity(intent);
                //getActivity().overridePendingTransition(android.R.anim.slide_out_right, android.R.anim.slide_out_right);
            }
        });
        return view;
    }

    private void showExitDialog(Activity activity){
        myDialog = new AlertDialog.Builder(activity).create();
        myDialog.show();
        myDialog.getWindow().setContentView(R.layout.exit_dialog);
        myDialog.getWindow().findViewById(R.id.change_account_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), LoginActivity.class);
                startActivity(intent);
            }
        });
        myDialog.getWindow().findViewById(R.id.exit_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }

}
